# -*- coding: utf-8 -*-
# @Time : 2025/06/16 22:28:10
# @Desc :  生成 appISSID 打包唯一编号。
# @Author : Sean
# @File   : getAppISSID.py

from pathlib import Path
import sys

sys.path.insert(0, str(Path().absolute()))

import random
from config.config import Config
from utils.common import get_resource_path


class GetAPPISSID:
    """生成 appISSID 打包唯一编号"""

    def getItem(self, k=4):
        """从0123456789ABCDEF中随机获取k个字符组成一个新的字符串"""
        itemList = random.choices(population="0123456789ABCDEF", k=k)
        return "".join(itemList)

    def APPISSID(self):
        """生成 appISSID 打包唯一编号"""
        appISSID = Config.appISSID
        if appISSID == "":
            config_file_path = get_resource_path("config/config.py")
            # 读取文件内容
            with open(config_file_path, "r", encoding="utf-8") as file:
                configContent = file.read()
            product_appISSID = (
                "{{"
                + f"{self.getItem(8)}-{self.getItem(4)}-{self.getItem(4)}-{self.getItem(4)}-{self.getItem(12)}"
                + "}"
            )
            configContent = configContent.replace(
                'appISSID = ""', f"appISSID = '{product_appISSID}'"
            )
            with open(config_file_path, "w", encoding="UTF-8") as f:
                f.write(configContent)
        return appISSID
